﻿using BenchmarkDotNet.Running;
using KdbndpTest.BenchmarkRunner;
using KdbndpTest.Demo;
using SqlSugar;
using DbType = SqlSugar.DbType;


// 单元测试
//Demo0_SqlSugarClient.Init();
//Demo1_Queryable.Init();
//Demo2_Updateable.Init();
//Demo3_Insertable.Init();
//Demo4_Deleteable.Init();
//Demo5_SqlQueryable.Init();

// 基准测试
var querySummary = BenchmarkRunner.Run<Demo1_Insertable>();
var updateSummary = BenchmarkRunner.Run<Demo3_Queryable>();
var insertSummary = BenchmarkRunner.Run<Demo3_Insertable>();
var deleteSummary = BenchmarkRunner.Run<Demo4_DeleteableRunner>();

Console.WriteLine("all successfully.");
Console.ReadKey();


/// <summary>
/// Helper class for database operations
/// 数据库操作的辅助类
/// </summary>
public class DbHelper
{
    /// <summary>
    /// Database connection string
    /// 数据库连接字符串
    /// </summary>
    public readonly static string Connection = "PORT=54321;DATABASE=event_sqlsugar;HOST=localhost;PASSWORD=root#123;USER ID=postgres";

    /// <summary>
    /// Get a new SqlSugarClient instance with specific configurations
    /// 获取具有特定配置的新 SqlSugarClient 实例
    /// </summary>
    /// <returns>SqlSugarClient instance</returns>
    public static SqlSugarClient GetNewDb()
    {
        var db = new SqlSugarClient(new ConnectionConfig()
        {
            IsAutoCloseConnection = true,
            DbType = DbType.Kdbndp,
            ConnectionString = Connection,
            LanguageType = LanguageType.Default,//Set language
            MoreSettings = new ConnMoreSettings()
            {
                DatabaseModel = DbType.PostgreSQL
            },
        },
        it =>
        {
            // Logging SQL statements and parameters before execution
            // 在执行前记录 SQL 语句和参数
            it.Aop.OnLogExecuting = (sql, para) =>
            {
                Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
            };
        });
        return db;
    }
}
